package com.mitgroup.dmrvs.view;

import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

public class SplashLoadDataTask extends AsyncTask<Void, Void, Integer> {

    private String TAG = SplashLoadDataTask.class.getSimpleName();

    private LoadDataCallback callback;

    private Context mContext;

    public SplashLoadDataTask(LoadDataCallback callback, AppCompatActivity context) {
        mContext = context;
        this.callback = callback;
    }
    @Override
    protected Integer doInBackground(Void... params) {
        int status = 0;
        // 在此执行耗时任务，可根据任务（数据加载）执行状态给status赋不同的值。
        try{

        } catch (Exception e){
            status = 1;
            Log.e(TAG, e.toString());
        }
        return status;
    }
    @Override
    protected void onPostExecute(Integer status) {
        super.onPostExecute(status);
        if (status == 0) {
            callback.loaded();
        } else if (status == 1) {
            callback.loadError();
        }
    }

    /**
     * 加载数据回调
     */
    public interface LoadDataCallback {
        /**
         * 数据加载完毕
         */
        void loaded();

        /**
         * 数据加载出错
         */
        void loadError();
    }

}